package pers.lls.hds.sort.select;


import java.util.Arrays;

/**
 * 选择排序
 *
 * @author lilichai
 */
public class SelectSort {

    public void selectionSort(long[] arr) {
        int i, j, min;
        for (i = 0; i < arr.length - 1; i++) {
            min = i;
            for (j = i + 1; j < arr.length; j++) {
                if (arr[j] < arr[min]) {
                    min = j;
                }
            }
            long temp = arr[i];
            arr[i] = arr[min];
            arr[min] = temp;
        }
    }

    public static void main(String[] args) {
        SelectSort sort = new SelectSort();
        long[] arr = {1,2,3,5,6,7,4};
        sort.selectionSort(arr);
        Arrays.stream(arr).forEach(d -> System.out.print(" " + d));
    }
}

